<template>
	<!-- 我的 -->
	<view class="my">
		<!-- <u-navbar title="" :is-back="false" :background="{background: '#0093dd' }" :border-bottom="false">
		</u-navbar> -->
		<view class="head-box">
			<view class="user ">
				<view class="user-top-box">
					<!-- 头像栏 -->
					<view class="left-box">
						<u-avatar class="header-img" :src="imageUrl(user.avatar)" size="large"
							@click="navTo('/pages/sys/user/info')"></u-avatar>
					</view>
					<view class="right-box">
						<text class="flex name">{{user.name}}</text>
						<text class="text-28 mt-10">账号：{{user.userName}}</text>
					</view>
				</view>

				<view class="user-bottom-box">
					<!-- 签名 -->
					<view class="flex-row pb-20 ">
						<text class="text-26 introduce">你的倒影是我带不走的风景，就像居无定所的云还在旅行！</text>
					</view>
					<view class="flex pb-20 " v-if="user.roleKey=== 'operatorUser'">
						<view class="official">
							<view class="circular-box">
								<image class="official-imgae" :src="'/static/aidex/images/official.png'"></image>
							</view>
							<view style="margin-left: 5rpx;">官方认证：地区运营</view>
						</view>
					</view>
				</view>
			</view>
		</view>


		<!-- 统计栏 -->
		<view class="middle">
			<view class="middle-box">
				<view class="wrap-card flex items-center">
					<view v-for="(item,index) in countList" :key="index"
						class="flex-1 flex flex-col items-center justify-center">
						<view class="text-32 font-bold">
							{{item.num}}
						</view>
						<view class="text-28 text-gray-500 mt-10">
							{{item.name}}
						</view>
					</view>
				</view>

			</view>
		</view>

		<!-- 广告位 -->
		<view class="advertisement">
			<image class="adv-img rounded-20 " src="/static/platform/svg/banner.svg" mode="aspectFill"></image>
		</view>

		<view class="operation">
			<!-- 管理栏 -->
			<scroll-view scroll-x="true" class="scroll-box">
				<view class="management" :style="{ '--management-num': managementList.length }">
					<view class="item" v-for="(item,index) in managementList" :key="index"
						@click="navTo(item.url,item.type==='param'?user.id:'')">
						<view class="item-head">
							<u-icon class="icon" :name="item.icon" size="32"></u-icon>
							<view>{{item.title}}</view>
						</view>
						<view class="item-bottom">{{item.content}}</view>
					</view>
				</view>
			</scroll-view>

			<!-- 操作栏 -->
			<view class="list">
				<view class="list-box">
					<u-grid :col="4" :border="false">
						<u-grid-item v-for="(item,index) in settingList" :key="index"
							@click="navTo(item.url,item.type==='param'?user.id:'')">
							<u-icon :name="item.icon" :size="46" :color="item.color"></u-icon>
							<view class="grid-text mt-10">{{item.title}}</view>
						</u-grid-item>
					</u-grid>
				</view>
			</view>
		</view>
		<buttom-tabbar></buttom-tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 统计列表
				countList: [{
						num: 0,
						name: '帖子'
					},
					{
						num: 0,
						name: '评论'
					},
					{
						num: 0,
						name: '点赞'
					},
					{
						num: 0,
						name: '获赞'
					}
				],
				//管理
				managementList: [{
						icon: 'home',
						title: '个人中心',
						content: '个人空间信息',
						url: '/pages/platform/user/user-space?uid=',
						type: 'param'

					},
					{
						icon: 'edit-pen',
						title: '创作中心',
						content: '作品收益管理',
						url: '/pages/platform/post/post-management?uid=',
						type: 'param'

					},
					{
						icon: 'integral',
						title: '运营申请',
						content: '申请成为运营者',
						url: '/pages/platform/apply/operator-apply',
						isRole: true,
						type: 'none'

					},
					{
						icon: 'coupon',
						title: '支付中心',
						content: '官方充值渠道',
						url: ''

					},
					{
						icon: 'download',
						title: '游戏中心',
						content: '游戏下载地址',
						url: ''

					}
				],
				//设置
				settingList: [{
						icon: 'question-circle',
						color: '#733cff',
						url: '/pages/sys/user/problem',
						title: '常见问题',
						type: 'none'
					},
					{
						icon: 'kefu-ermai',
						color: '#27c0dc',
						url: '/pages/sys/user/comment',
						title: '意见反馈',
						type: 'none'
					},
					{
						icon: 'map',
						color: '#ff5500',
						url: '/pages/sys/user/pwd',
						title: '账号安全',
						type: 'none'
					},
					{
						icon: 'order',
						color: '#dcdc00',
						url: '/pages/sys/user/clear-cache',
						title: '清除缓存',
						type: 'none'
					},
					{
						icon: 'account',
						color: '#ff8d06',
						url: '/pages/sys/user/about',
						title: '关于我们',
						type: 'none'
					},
					{
						icon: 'kefu-ermai',
						color: '#ffaaff',
						url: '/pages/sys/user/service',
						title: '联系客服',
						type: 'none'
					},
					{
						icon: 'setting',
						color: '#2767dc',
						url: '/pages/sys/user/setting',
						title: '系统设置',
						type: 'none'
					}
				],
				user: {}
			}
		},
		computed: {

		},
		// 监听导航栏按钮点击
		onNavigationBarButtonTap() {
			this.goSet()
		},
		created() {
			this.init()
		},
		methods: {

			init() {
				this.getUserInfo()
			},
			getUserInfo() {
				this.$u.api.user.getInfoByUserId({
					userId: this.vuex_user.id
				}).then(res => {
					this.user = res.data
					this.countList[0].num = this.user.publishPostNumber
					this.countList[1].num = this.user.publishCommentNumber
					this.countList[2].num = this.user.likeNumber
					this.countList[3].num = this.user.beLikeNumber
					if (this.user.roleKey === 'operatorUser') {
						this.managementList.splice(this
							.managementList.findIndex(item => item.isRole === true), 1)
					}
				})
			},
			navTo(url, param) {
				if (param) {
					url = url + param
				}
				uni.navigateTo({
					url: url
				});
			},
			logout() {
				this.$u.api.logout().then(res => {
					this.$u.toast(res.msg);
					if (res.code == '200' || res.code == '401') {
						let self = this;
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/sys/login/index'
							});
						}, 500);
					}
				});
			},
			upgrade() {
				// #ifdef APP-PLUS
				this.$u.api.upgradeCheck().then(res => {
					if (res.result == 'true') {
						uni.showModal({
							title: '提示',
							content: res.message + '是否下载更新？',
							showCancel: true,
							success: function(res2) {
								if (res2.confirm) {
									plus.runtime.openURL(res.data.apkUrl);
								}
							}
						});
					} else {
						this.$u.toast(res.message);
					}
				});
				// #endif
				// #ifndef APP-PLUS
				this.$u.toast('小程序端或H5端无需检查更新')
				// #endif
			},
			imageUrl(itemUrl) {
				return this.handleUrl(itemUrl)
			},
			goSet() {
				this.$u.route('/pages/mine/set')
			},
			goPage(url) {
				if (url) this.$u.route('/pages/mine/' + url)
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #F6F5FA;
	}

	.my {

		.head-box {
			background-color: #0093dd;
			padding: 32rpx 32rpx 100rpx;
			flex-direction: row;
			display: flex;


			.user {
				display: flex;
				flex-direction: column;

				.user-top-box {
					display: flex;

					.left-box {
						display: flex;

						.header-img {
							width: 150rpx;
							height: 150rpx;

						}
					}

					.right-box {
						color: #fff;
						margin-left: 30rpx;
						flex-direction: column;
						display: flex;

						.name {
							font-size: 18px;
							font-weight: 700;
						}
					}
				}

				.user-bottom-box {
					color: #fff;
					margin-top: 20rpx;
					display: flex;
					flex-wrap: wrap;
					flex-direction: column;

					.official {
						background: #399cdd;
						display: flex;
						padding: 10rpx;
						font-size: 13px;
						line-height: 20px;

						.circular-box {
							display: flex;
							justify-content: center;
							align-items: center;

							width: 35rpx;
							height: 35rpx;
							margin: 5rpx;
							background-color: #ffffff;
							border-radius: 50%;


							.official-imgae {
								display: flex;
								width: 14px;
								height: 14px;

							}


						}



					}
				}


			}
		}



		.middle {
			margin-top: -60rpx;
			padding: 0 32rpx;

			.middle-box {
				padding: 32rpx 0;
				background-color: #fff;
				border-radius: 20rpx;
				box-shadow: 0 0 10rpx rgba($color: #eaeaea, $alpha: 0.2);
				flex-direction: row;
				justify-content: space-around;
			}
		}

		.advertisement {
			margin: 32rpx 10rpx;
			padding: 15rpx;
			background-color: #fff;
			border-radius: 20rpx;

			.adv-img {
				display: flex;
				justify-content: center;
				align-items: center;
				height: 200rpx;
				width: 100%;

			}
		}

		.operation {
			padding: 10rpx 0;
			background-color: #fff;
			border-radius: 36rpx;

			.scroll-box {
				margin-top: 30rpx;
				width: 100%;

				.management {
					width: calc(var(--management-num) * 220rpx);
					display: flex;


					.item {
						width: 220rpx;
						margin: 0 10rpx;
						border-radius: 16rpx;
						padding: 10rpx 20rpx;
						background-color: #F5F8F9;
						display: flex;
						flex-direction: column;

						.item-head {
							font-size: 14px;
							display: flex;
							font-weight: 700;
							margin: 10rpx 0;

							.icon {
								margin-right: 5rpx;
							}
						}

						.item-bottom {
							color: #999;
							font-size: 10px;
						}
					}

					.item:first-child {
						margin-left: 20rpx;
					}

					.item:last-child {
						margin-right: 20rpx;
					}

				}
			}



			.list-box {
				margin-top: 20rpx;
				padding: 0 10rpx;
				padding-top: 20rpx;
				background-color: #fff;
			}
		}


	}
</style>